import { PickerPopupActions } from "react-vant";
import {
  deleteHttp,
  getHttp,
  postHttp,
  postHttpHeaders,
  postHttpJSON,
  postHttpMulti,
  putHttp,
  putHttpJSON,
  putHttpParams,
} from "..";

//  我的档案（添加-编辑） 档案数据类型
interface myProFileRawState {
  diseaseBefore: string;
  diseaseMain: string;
  diseaseNow: string;
  archivesId: number;
  picture: string;
  treatmentEndTime: number;
  treatmentHospitalRecent: string;
  treatmentProcess: string;
  treatmentStartTime: number;
  userId: number;
}

//  我的档案（添加-编辑） picker数据类型
interface PickerRawState {
  type: string;
  tooltip: string;
  dateTime: string;
  actions?: PickerPopupActions;
}

/********************************** 我的消息 *********************************/
// 定义查询用户系统通知列表
export const getSystemNoticeList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findSystemNoticeList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义查询用户问诊通知列表
export const getInquiryNoticeList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findInquiryNoticeList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义查询用户H币通知列表
export const getHealthyCurrencyNoticeList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findHealthyCurrencyNoticeList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义查询用户未读消息数
export const getUserNoticeReadNum = (userId: number, sessionId: string) =>
  getHttp(
    "/health/user/verify/v1/findUserNoticeReadNum",
    {},
    {
      userId,
      sessionId,
    }
  );

// 定义修改消息状态为全部已读
export const putModifyAllStatus = (userId: number, sessionId: string) =>
  putHttp(
    "/health/user/verify/v1/modifyAllStatus",
    {},
    {
      userId,
      sessionId,
    }
  );

/********************************** 我的档案 *********************************/
//  定义获取用户自己档案的函数
export const getProFile = (userId: number, sessionId: string) =>
  getHttp(
    "/health/user/verify/v1/findUserArchives",
    {},
    {
      userId,
      sessionId,
    }
  );

// 定义添加用户档案的函数
export const addProFile = (
  pickerList: PickerRawState[],
  myProFile: myProFileRawState,
  userId: number,
  sessionId: string
) =>
  postHttpJSON(
    "/health/user/verify/v1/addUserArchives",
    {
      diseaseMain: myProFile.diseaseMain,
      diseaseNow: myProFile.diseaseNow,
      diseaseBefore: myProFile.diseaseBefore,
      treatmentHospitalRecent: myProFile.treatmentHospitalRecent,
      treatmentProcess: myProFile.treatmentProcess,
      treatmentStartTime: pickerList[0].dateTime,
      treatmentEndTime: pickerList[1].dateTime,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义删除用户档案的函数
export const deleteProFile = (
  archivesId: number,
  userId: number,
  sessionId: string
) =>
  deleteHttp(
    "/health/user/verify/v1/deleteUserArchives",
    { archivesId },
    {
      userId,
      sessionId,
    }
  );

//  定义上传用户档案相关图片的函数
export const uploadArchivesPicture = (
  id: number,
  archivesId: number,
  picture: File,
  userId: number,
  sessionId: string
) =>
  postHttpMulti(
    "/health/user/verify/v1/uploadArchivesPicture",
    { archivesId: id || archivesId, picture },
    { userId, sessionId }
  );

//  定义修改用户档案的函数
export const updateProFile = (
  pickerList: PickerRawState[],
  myProFile: myProFileRawState,
  archivesId: number,
  userId: number,
  sessionId: string
) =>
  putHttpJSON(
    "/health/user/verify/v1/updateUserArchives",
    {
      archivesId,
      diseaseMain: myProFile.diseaseMain,
      diseaseNow: myProFile.diseaseNow,
      diseaseBefore: myProFile.diseaseBefore,
      treatmentHospitalRecent: myProFile.treatmentHospitalRecent,
      treatmentProcess: myProFile.treatmentProcess,
      treatmentStartTime: pickerList[0].dateTime,
      treatmentEndTime: pickerList[1].dateTime,
    },
    {
      userId,
      sessionId,
    }
  );

//  定义查询我的被采纳建议的函数
export const getAdoptIdeas = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findMyAdoptedCommentList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

//  定义查看我的病友圈发帖列表的函数
export const getMySickCircleList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/sickCircle/verify/v1/findMySickCircleList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

//  定义查询我的病友圈帖子的评论列表的函数
export const getMySickCircleCommentList = (
  sickCircleId: number,
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/sickCircle/verify/v1/findMySickCircleCommentList",
    { sickCircleId, page, count },
    { userId, sessionId }
  );

//  定义查询我的被采纳的建议(病友圈_医生端)的函数
export const getMyAdoptedCommentList_doctor = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/doctor/verify/v1/findMyAdoptedCommentList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

//  定义采纳病友圈优秀的评论的函数
export const adoptionProposal = (
  commentId: number,
  sickCircleId: number,
  userId: number,
  sessionId: string
) =>
  putHttp(
    "/health/user/sickCircle/verify/v1/adoptionProposal",
    {
      commentId,
      sickCircleId,
    },
    {
      userId,
      sessionId,
    }
  );

//  定义生成邀请码的函数
export const generateInvitationCode = (userId: number, sessionId: string) =>
  postHttp(
    "/health/user/verify/v1/makeInvitationCode",
    {},
    {
      userId,
      sessionId,
    }
  );

//  定义查询用户邀请码的函数
export const getUserInvitationCode = (userId: number, sessionId: string) =>
  getHttp(
    "/health/user/verify/v1/findUserInvitationCode",
    {},
    { userId, sessionId }
  );

//  定义查询用户购买视频列表的函数
export const getUserVideoBuyList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findUserVideoBuyList",
    { page, count },
    { userId, sessionId }
  );

//  定义删除购买健康课堂视频的函数
export const deleteVideoBuy = (
  videoId: number,
  userId: number,
  sessionId: string
) =>
  deleteHttp(
    "/health/user/verify/v1/deleteVideoBuy",
    { videoId },
    { userId, sessionId }
  );

//  定义用户取消视频收藏的函数
export const cancelVideoCollection = (
  videoId: number,
  userId: number,
  sessionId: string
) =>
  deleteHttp(
    "/health/user/verify/v1/cancelVideoCollection",
    { videoId },
    {
      userId,
      sessionId,
    }
  );

/********************************** 我的收藏 *********************************/
// 定义查询用户资讯收藏列表
export const getUserInfoCollectionList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findUserInfoCollectionList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义用户收藏健康课堂视频列表
export const getVideoCollectionList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) =>
  getHttp(
    "/health/user/verify/v1/findVideoCollectionList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义查询用户收藏病友圈列表
export const getUserSickCollectionList = (
  page: number,
  count: number,
  userId: number,
  sessionId: string
) => getHttp(
  "/health/user/verify/v1/findUserSickCollectionList",
  {
    page,
    count
  },
  {
    userId,
    sessionId
  }
)
// 定义取消病友圈收藏
export const cancelSickCollection = (
  sickCircleId: number,
  userId: string,
  sessionId: string
) => deleteHttp(
  "/health/user/verify/v1/cancelSickCollection",
  {
    sickCircleId
  },
  {
    userId,
    sessionId
  }
)

/********************************** 我的任务 *********************************/
// 用户签到
export const getMyAssignmentaddSign = (userId: number, sessionId: string) =>
  postHttpHeaders("/health/user/verify/v1/addSign", {
    userId,
    sessionId,
  });
// 查看用户当天是否签到
export const getWhetherSign = (userId: number, sessionId: string) =>
  getHttp("/health/user/verify/v1/whetherSignToday", {
    userId,
    sessionId,
  });

//查看连续签到的天数
export const getcontinuationSign = (userId: number, sessionId: string) =>
  getHttp("/health/user/verify/v1/findUserSign", {
    userId,
    sessionId,
  });

//  定义发送邮箱验证码的函数
export const sendOutEmailCode = (email: string) =>
  postHttp("/health/user/v1/sendOutEmailCode", { email });

//  定义校验验证码的函数
export const checkCode = (email: string, code: string) =>
  postHttp("/health/user/v1/checkCode", { email, code });

//  定义重置用户密码的函数
export const resetUserPwd = (email: string, pwd1: string, pwd2: string) =>
  putHttpParams("/health/user/v1/resetUserPwd", { email, pwd1, pwd2 });

/********************************** 我的任务 *********************************/
// 定义用户签到
export const postaddSign = (userId: number, sessionId: string) =>
  postHttpHeaders("/health/user/verify/v1/addSign", {
    userId,
    sessionId,
  });
// 定义做任务
export const postDoTask = (taskId: number, userId: number, sessionId: string) =>
  postHttp(
    "/health/user/verify/v1/doTask",
    {
      taskId,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义查询用户任务列表
export const getFindUserTaskList = (userId: number, sessionId: string) =>
  getHttp(
    "/health/user/verify/v1/findUserTaskList",
    {},
    {
      userId,
      sessionId,
    }
  );

// 定义领取任务奖励
export const postReceiveReward = (
  taskId: number,
  userId: number,
  sessionId: string
) =>
  postHttp(
    "/health/user/verify/v1/receiveReward",
    {
      taskId,
    },
    {
      userId,
      sessionId,
    }
  );
/*********************************** 我的关注 *********************************/
// 关注医师数据
export const getFollowPhysician = (
  userId: number,
  sessionId: string,
  page: number,
  count: number
) =>
  getHttp(
    "/health/user/verify/v1/findUserDoctorFollowList",
    {
      page,
      count,
    },
    {
      userId,
      sessionId,
    }
  );

//取消关注
export const deleteCancelFollow = (userId: number, sessionId: string, doctorId: number) => deleteHttp(
  "/health/user/inquiry/verify/v1/cancelFollow",
  {
    doctorId
  },
  {
    userId,
    sessionId
  }
)


/*********************************** 设置 *********************************/
//  定义上传头像的函数
export const modifyHeadPic = (userId: number, sessionId: string, image: File) =>
  postHttpMulti(
    "/health/user/verify/v1/modifyHeadPic",
    {
      image,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义根据用户ID查询用户信息
export const getUserInfoById = (userId: number, sessionId: string) =>
  getHttp(
    "/health/user/verify/v1/getUserInfoById",
    {},
    {
      userId,
      sessionId,
    }
  );

// 定义完善用户信息
export const updatePerfectUserInfo = (
  age: number,
  height: number,
  weight: number,
  userId: number,
  sessionId: string
) =>
  putHttpParams(
    "/health/user/verify/v1/perfectUserInfo",
    {
      age,
      height,
      weight,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义修改用户性别
export const updateUserSex = (sex: number, userId: number, sessionId: string) =>
  putHttpParams(
    "/health/user/verify/v1/updateUserSex",
    {
      sex,
    },
    {
      userId,
      sessionId,
    }
  );

// 定义修改用户昵称
export const updateNickName = (
  nickName: string,
  userId: number,
  sessionId: string
) =>
  putHttpParams(
    "/health/user/verify/v1/modifyNickName",
    {
      nickName,
    },
    {
      userId,
      sessionId,
    }
  );


//修改密码

export const putChangePassword = (
  userId: number,
  sessionId: string,
  oldPwd: string,//原密码
  newPwd: string//新密码
) =>
  putHttpParams(
    "/health/user/verify/v1/updateUserPwd",
    {
      oldPwd,
      newPwd
    },
    {
      userId,
      sessionId,
    }
  );




